﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using Model;
namespace UI
{
    public partial class 商品修改 : Form
    {
        public 商品修改()
        {
            InitializeComponent();
        }

        private void 商品修改_Load(object sender, EventArgs e)
        {
            //执行操作
            DataSet da = 商品修改BLL.ProductType();
           
            //将虚拟内存的值赋给控件
            this.comboBox1.DataSource = da.Tables[0];
            //隐藏值
            this.comboBox1.ValueMember = "PTID";
            //显示值
            this.comboBox1.DisplayMember = "PTName";

            foreach (DataRow item in da.Tables[0].Rows)
            {
                if (item["PTName"].ToString() == Products.PTName)
                {
                    this.comboBox1.Text = Products.PTName;
                }
            }
            
            //赋值
            textBox1.Text = Products.ProductName;

            textBox3.Text = Products.ProductJP;
            textBox4.Text = Products.ProductPrice;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //关闭本窗体
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox3.Text =="" || textBox4.Text =="")
            {
                MessageBox.Show("请填写完整信息");
                return;
            }
            //传值
            Products.ProductName = textBox1.Text;
            Products.PTID =comboBox1.SelectedValue.ToString();
            Products.ProductJP = textBox3.Text;
            Products.ProductPrice = textBox4.Text;
            //执行操作
            int count = 商品修改BLL.ProductsUpdate();
            if (count > 0)
            {
                MessageBox.Show("修改成功");
                new 商品设置().Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }
    }
}
